﻿using System.IO;

namespace Ultima.Xna.Data
{
    public class Verdata
    {
        private static IndexEntry5D[] _patches;
        private static Stream _stream;

        public static Stream Stream { get { return _stream; } }
        public static IndexEntry5D[] Patches { get { return _patches; } }

        static Verdata()
        {
            string path = FileManager.GetFilePath("verdata.mul");

            if (!File.Exists(path))
            {
                _patches = new IndexEntry5D[0];
                _stream = Stream.Null;
            }
            else
            {
                _stream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read);
                BinaryReader bin = new BinaryReader(_stream);

                _patches = new IndexEntry5D[bin.ReadInt32()];

                for (int i = 0; i < _patches.Length; ++i)
                {
                    _patches[i].File = bin.ReadInt32();
                    _patches[i].Index = bin.ReadInt32();
                    _patches[i].Lookup = bin.ReadInt32();
                    _patches[i].Length = bin.ReadInt32();
                    _patches[i].Extra = bin.ReadInt32();
                }
            }
        }
    }
}